﻿//------------------------------------------------------------------------------ 
// <copyright file="JQueryExtendControl.cs" company="Fm Computer">
//     Copyright (c) Fm Computer di Menatti Fulvia.  All rights reserved.
// </copyright>
//----------------------------------------------------------------------------- 
namespace FmjQuery
{
    using System;
    using System.ComponentModel;
    using System.Web.UI;

    /// <summary>
    /// Base control for extend with jQuery
    /// </summary>
    public abstract class JQueryExtendControl : JQueryBaseControl, IjExtender
    {
        #region Fields
        /// <summary>
        /// Client id target control
        /// </summary>
        private string ttargetClientID = string.Empty;
        #endregion

        #region Property
        /// <summary>
        /// Gets or sets id of target control
        /// </summary>
        [Description("Name of control that extend")]
        public string TargetControlID
        {
            get; set;
        }

        /// <summary>
        /// Gets client id of target control
        /// </summary>
        [Description("Get client id of target control")]
        public string TargetControlClientID 
        {
            get
            {
                return this.ttargetClientID;
            }
        }
        #endregion

        #region Override
        /// <summary>
        /// Register control to JQueryManager
        /// </summary>
        protected override void RegisterWithjQueryManager()
        {
            if (string.IsNullOrEmpty(this.TargetControlID))
            {
                throw new InvalidOperationException("You must set TargetControlID");
            }

            Control ctrl = FindControl(this.TargetControlID);

            if (ctrl == null)
            {
                throw new InvalidOperationException("Invalid TargetControlID");
            }

            this.ttargetClientID = ctrl.ClientID;

            base.RegisterWithjQueryManager();
        }
        #endregion
    }
}
